package com.bj58.ecdata.monitor;

import org.eclipse.jetty.server.Server;
import org.slf4j.LoggerFactory;

import com.bj58.ecdata.webframework.AbstractServer;
import com.bj58.ecdata.webframework.Config;

import ch.qos.logback.classic.LoggerContext;

public class MonitorService extends AbstractServer {
	public static MonitorService instance;

	public static Server getJettyServer() {
		return instance.server;
	}

	public MonitorService(String[] anArgs) {
		super(anArgs);
	}

	@Override
	public void init(Config config, String[] args) {
		config.setMin_thread(128);
		config.setMax_thread(512);
		config.setContextPath("/");
		config.setScanclass("com.bj58.ecdata.monitor");
		config.setProjectName(args[0]);

		int port = 8888;
		if (args.length > 1)
			port = Integer.parseInt(args[1]);
		if (args.length > 2)
			config.setTempDir(args[2]);
		config.setPort(port);
		// ZKManager.init(zkAddress, idcName, port);

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		runServer(args);
	}

	public static void runServer(String... args) throws Exception {

		if (args == null || args.length < 1) {
			throw new RuntimeException("server args is error");
		}
		String projectName = args[0];

		LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
		context.setPackagingDataEnabled(false);
		context.setName(projectName);

		MonitorService server = new MonitorService(args);
		instance = server;
		server.run(args);
	}

}
